home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6940 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  57 lines

  1. Path: news.clark.net!not-for-mail
  2. From: gusty@clark.net (Harlan Messinger)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Is there a standard for * and & placement style?
  5. Date: 20 Feb 1996 14:04:21 GMT
  6. Organization: Clark Internet Services, Inc., Ellicott City, MD USA
  7. Message-ID: <4gckd5$bc7@clarknet.clark.net>
  8. References: <3128BD31.4AF8@wildfire.com> <marnoldDn27q9.Is0@netcom.com>
  9. NNTP-Posting-Host: explorer.clark.net
  10. Mime-Version: 1.0
  11. Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  12. Content-Transfer-Encoding: 8bit
  13.  
  14. Matt Arnold (marnold@netcom.com) wrote:
  15. : My personal preference is Form 1, and I have a logical reason:  It
  16. : seems to me that that "pointer-ness" (*) or "reference-ness" (&) is
  17. : certinaly part of the variable *type*, not part of the variable.  It
  18. : therefore seems logical to associate * or & with type identifier 
  19. : rather than the variable name.  For me, this creates a distinct 
  20. : visual separation between types and variables.
  21.  
  22. I agree with you that I would _like_ the * and the & to be appended to 
  23. the base type. However, the syntax of pointer and reference type 
  24. declarations itself associates the * and the & with the variable names, 
  25. as can be seen when multiple variables are declared on the same line.
  26.  
  27.     char* p, q;
  28.  
  29. may appear to declare two variables, each a (char*), but that is not the 
  30. case. Instead, p is (char*) and q is char. To get both of them to be 
  31. (char*), we need
  32.  
  33.     char *p, *q;
  34.  
  35. Adding more complexity,
  36.  
  37.     char a, b, *c, *d, &e = a;
  38.  
  39. declares a and b as char, c and d as (char*), and e as (char&).
  40.  
  41. I think the syntax is dumb in the first place. One declaration statement 
  42. should declare variables of one type. I think
  43.  
  44.     char* a, b, c;
  45.  
  46. should declare three (char*) variables. If someone also wants a char 
  47. variable d, then that should be on two lines:
  48.  
  49.     char *a, b, c;
  50.     char d;
  51.  
  52. But that's not what they gave us. For this reason, I've wound up using the
  53. "char *x" format, and it recently occurred to me, even though I've never
  54. declared multiple references on one line, that "char &y" would be
  55. consistent. 
  56.  
  57.